//
//  RadioOptionCell.swift
//  Aiwei
//
//  Created by zhu xietong on 2018/1/4.
//  Copyright © 2018年 zhu xietong. All rights reserved.
//

import UIKit
import Eelay

open class RadioOptionCell: JoTableCell {
    
    public var field = TagsOptionField<RadioKit>()
    
    open override func addLayoutRules() {
        contentView.eelay = [
            [field,[ee.T.L.B,[2,AppTheme.edge,-2]]],
        ]
        field.tagsV.preferredMaxLayoutWidth = Swidth - (2 * AppTheme.edge)
    }
    
    open override func mo_model_reload() {
        field.controller = self.content_controller
        if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.fields).0", mo.model)
        {
            field.mo.model = f
        }
        
    }

    open override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }

}


open class RadioKit:FOptionV{
    open override func setOptionLayout() {
        self.edeg = UIEdgeInsets(top: 2, left: 6, bottom: 2, right: 6)
        eelay = [
            [imgV,[ee.Y.L],"18",18],
            [titleL,[ee.Y],[imgV,ee.R,ee.L,8],[ee.R]],
            [bt,[ee.T.L.B.R]],
        ]
        
        bt.setContentConstrainToLowLever()
        imgV.setImage(UIImage(named:"radio_check_n"), for: .normal)
        imgV.setImage(UIImage(named:"radio_check_s"), for: .selected)
        _ = titleL.ui.left.font13.cl_666
    }
    open override var intrinsicContentSize: CGSize
    {
        let s_w = self.titleL.intrinsicContentSize.width + edeg.left + edeg.right + 20 + 8
        return [s_w,36]
    }
    
    open override func mo_model_reload() {
        titleL.text = mo.model["name",""]
        if mo.model[FK.selected,"NO"] == "YES"
        {
            imgV.isSelected =  true
        }
        else
        {
            imgV.isSelected = false
        }
        
        bt.setImage(nil, for: .normal)
        bt.setImage(nil, for: .selected)
    }
}
